home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Date: 8 Mar 1996 17:57:01 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4hqhge$2gu@solutions.solon.com>
- References: <4g0elg$mdr@redstone.interpath.net> <4hpd8a$d70@alterdial.UU.NET> <1996Mar8.153250.115645@kuhub.cc.ukans.edu>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <1996Mar8.153250.115645@kuhub.cc.ukans.edu>,
- <anh@kuhub.cc.ukans.edu> wrote:
- >Well, I found one good use of magic numbers such as when one needs a
- >localized temporary buffer of data.
-
- >int func()
- >{
- > FILE *fp;
- > char buf[15+1];
-
- > ...
-
- > fgets(buf,15,fp);
- >}
-
- >Well, if I know the data is always going to be less than 15 or whatever,
- >there is really no need to use a #define here.
-
- However, the +1 is redundant; fgets will read one *less* than the specified
- number of bytes, and will then use the last one for a trailing nul.
-
- Anyway, I'd rather see a 15 in both places, and over that, I'd prefer to
- see a #define or enum used. If you know the data is always going to be
- less than 15 chars, you know *why* it will be less than 15 chars, and it is
- because of some attribute of the data, which you need to describe here.
- So use a symbolic name, so that later, if the "object which can never be
- more than 14 chars" becomes an "object which can never be more than 28
- chars", you know to come looking for it here.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-